﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace YouYi.YingShengBack.IService
{
    public interface IBaseService<T> where T : class, new()
    {
        /// <summary>
        /// 通用单表添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Add(T entity);

        /// <summary>
        /// 通用单表修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Update(T entity);

        /// <summary>
        /// 通用单表删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool DelToClass(T entity);


        /// <summary>
        /// 通用单表批量删除
        /// </summary>
        /// <param name="entitys"></param>
        /// <returns></returns>
        bool DelToList(List<T> entitys);


        /// <summary>
        /// 通用id 批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        bool DelToArray(params int[] ids);

        /// <summary>
        /// 返回一个表数据集合
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        List<T> SetList(Expression<Func<T, bool>> expression);

        /// <summary>
        /// 返回一个记录
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        T Set(Expression<Func<T, bool>> expression);

        /// <summary>
        /// 判断记录是否存在
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        bool Exist(Expression<Func<T, bool>> expression);

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="where"></param>
        /// <param name="orderBy"></param>
        /// <param name="count"></param>
        /// <param name="isAsc"></param>
        /// <returns></returns>
        List<T> SetPageList<TY>(int page, int limit, Expression<Func<T, bool>> where, Expression<Func<T, TY>> orderBy, out int count, bool isAsc = true);
        /// <summary>
        /// 返回总数
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        int Count(Expression<Func<T, bool>> where);
    }
}
